package com.heer.gymnasium.module.main.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.heer.amap.utils.ToastUtil;
import com.heer.gymnasium.R;
import com.heer.gymnasium.constant.Extras;
import com.heer.gymnasium.module.advise.beans.AdMainBean;
import com.heer.gymnasium.module.article.beans.ArticleBean;
import com.heer.gymnasium.module.article.views.ArticleActivity;
import com.heer.gymnasium.module.article.views.ArticleStoreActivity;
import com.heer.gymnasium.module.coach.beans.CoachBean;
import com.heer.gymnasium.module.coach.views.CoachDetailActivity;
import com.heer.gymnasium.module.main.beans.CategoryBean;
import com.heer.gymnasium.module.main.beans.HomeBean;
import com.heer.gymnasium.module.main.views.CategoryActivity;
import com.heer.gymnasium.module.main.views.FindFragment;
import com.heer.gymnasium.module.main.views.MainActivity;
import com.heer.gymnasium.module.store.beans.StoreBean;
import com.heer.gymnasium.module.store.views.StoreActivity;
import com.heer.gymnasium.module.store.views.StoreListActivity;
import com.heer.gymnasium.util.ImageUtil;
import com.heer.gymnasium.util.StringUtils;
import com.heer.imagepick.DensityUtils;
import com.zhihuiyun.library.bannar.Banner;
import com.zhihuiyun.library.bannar.listener.OnBannerListener;
import com.zhihuiyun.library.bannar.loader.ImageLoader;
import com.zhihuiyun.library.commonadapter.QuickAdapter;
import com.zhihuiyun.library.commonadapter.QuickTypeAdapter;
import com.zhihuiyun.library.commonadapter.ViewHolder;
import com.zhihuiyun.library.commonadapter.quick.Quick;
import com.zhihuiyun.library.view.MyGridView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zy on 2018/1/17.
 */

public class HomeAdapter extends RecyclerView.Adapter implements Extras {

    private Context context;
    private HomeBean mData;
    private LayoutInflater inflater;
    private RequestManager requestManager;
    private ArrayList<Integer> typeList;

    private final int VIEW_TYPE_BANNER = 0xa;
    private final int VIEW_TYPE_CATEGORY = 0xb;
    private final int VIEW_TYPE_ARTICLE = 0xc;
    private final int VIEW_TYPE_STORE = 0xd;
    private final int VIEW_TYPE_COACH = 0xe;

    private final int DEFAULT_SHOW_SIZE_CATEGORY = 10;
    private final int DEFAULT_SHOW_SIZE_ARTICLE = 4;
    private final int DEFAULT_SHOW_SIZE_STORE = 5;
    private final int DEFAULT_SHOW_SIZE_COACH = 5;


    public HomeAdapter(Context _context) {
        context = _context;
        mData = new HomeBean();
        inflater = LayoutInflater.from(context);
        requestManager = Glide.with(context);
        typeList = new ArrayList<>();

        typeList.add(VIEW_TYPE_BANNER);
        typeList.add(VIEW_TYPE_CATEGORY);
        typeList.add(VIEW_TYPE_STORE);
        typeList.add(VIEW_TYPE_ARTICLE);
        typeList.add(VIEW_TYPE_COACH);

        Quick.init(new Quick.QuickLoad() {
            @Override
            public void load(Context context, String url, ImageView view) {
                ImageUtil.loadUrl(requestManager, url, R.drawable.banner, view);
            }
        });
    }

    public void setBannerData(List<AdMainBean> ads) {
        mData.setBannerData(ads);
        notifyDataSetChanged();
    }

    public void setCatogeryData(List<CategoryBean> catogeryData) {
//        mData.setCategoryData(catogeryData);
        mData.setCategoryData(new ArrayList<CategoryBean>());
        notifyDataSetChanged();
    }

    public void setArticleAd(AdMainBean ad) {
        mData.setArticleAd(ad);
        notifyDataSetChanged();
    }

    public void setArticleList(List<ArticleBean> articleList) {
        mData.setArticleList(articleList);
        notifyDataSetChanged();
    }

    public void setStoreAd(AdMainBean ad) {
        mData.setStoreAd(ad);
        notifyDataSetChanged();
    }

    public void setStoreList(List<StoreBean> storeList) {
        mData.setStoreList(storeList);
        notifyDataSetChanged();
    }

    public void setCoachAd(AdMainBean ad) {
        mData.setCoachAd(ad);
        notifyDataSetChanged();
    }

    public void setCoachList(List<CoachBean> coachList) {
        mData.setCoachList(coachList);
        notifyDataSetChanged();
    }
//

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = null;
        switch (viewType) {
            case VIEW_TYPE_BANNER:
                itemView = inflater.inflate(R.layout.holder_home_banner, null);
                break;
            case VIEW_TYPE_CATEGORY:
                MyGridView gridView = new MyGridView(context);
                gridView.setNumColumns(DEFAULT_SHOW_SIZE_CATEGORY / 2);
                gridView.setPadding(DensityUtils.dip2px(context, 15), 0, DensityUtils.dip2px(context, 15), 0);
                gridView.setBackgroundResource(R.color.white);
                gridView.setVerticalScrollBarEnabled(false);
                itemView = gridView;
                break;
            default:
                itemView = inflater.inflate(R.layout.holder_home_list_with_title, null);
                break;
        }
        return new HomeHolder(itemView, context, mData, viewType);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ((HomeHolder) holder).bindData(context, mData, typeList.get(position));
    }

    @Override
    public int getItemCount() {
        return typeList.size();
    }

    @Override
    public int getItemViewType(int position) {
        return typeList.get(position);
    }

    private class HomeHolder extends RecyclerView.ViewHolder {
        private View itemView;

        public HomeHolder(View itemView, Context context, HomeBean _data, int viewType) {
            super(itemView);
            this.itemView = itemView;
            bindData(context, _data, viewType);
        }

        public void bindData(Context context, HomeBean data, int viewType) {
            switch (viewType) {
                case VIEW_TYPE_BANNER:
                    fillBanner(context, data);
                    break;
                case VIEW_TYPE_CATEGORY:
                    fillCategory(context, data);
                    break;
                case VIEW_TYPE_ARTICLE:
                    fillArticle(context, data);
                    break;
                case VIEW_TYPE_STORE:
                    fillStore(context, data);
                    break;
                case VIEW_TYPE_COACH:
                    fillCoach(context, data);
                    break;
            }
        }


        private void fillBanner(Context context, HomeBean data) {
            List<AdMainBean> list = data.getBannerData();
            if (list != null) {
                final Banner banner = (Banner) itemView.findViewById(R.id.banner);
                bindBannerItem(itemView,
                        requestManager,
                        banner,
                        itemView.findViewById(R.id.holder_home_arrow_left_fl),
                        itemView.findViewById(R.id.holder_home_arrow_right_fl),
                        data.getBannerData());
            }
        }


        /**
         * 场地分类
         *
         * @param context
         * @param data
         */
        private void fillCategory(Context context, HomeBean data) {
            List<CategoryBean> list = data.getCategoryData();
            if (list != null && list.size() > 0) {
                if (list.size() > DEFAULT_SHOW_SIZE_CATEGORY - 1) {
                    list = list.subList(0, DEFAULT_SHOW_SIZE_CATEGORY - 1);
                }
                list.add(new CategoryBean());
                MyGridView gridView = (MyGridView) itemView;
                gridView.setAdapter(new QuickTypeAdapter<CategoryBean>(context, list, R.layout.item_category) {

                    @Override
                    public void bindData4View(ViewHolder holder, CategoryBean data, int type, int pos) {
                        if (pos < getCount() - 1) {
                            bindCategoryItem(context, holder, data, pos, getCount());
                        } else {
                            holder.getView(R.id.item_home_gridview_iv).setBackgroundResource(R.drawable.ic_home_more);
                            holder.getView(R.id.item_home_gridview_line_v).setVisibility(View.GONE);
                            holder.setText(R.id.item_home_gridview_tv, context.getResources().getString(R.string.more));

                            holder.getParentView().setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    CategoryActivity.startActivity(context);
                                }
                            });
                        }

                    }
                });
            } else {
            }
        }

        /**
         * 热门文章
         *
         * @param context
         * @param data
         */
        private void fillArticle(final Context context, HomeBean data) {
            final AdMainBean articleAd = data.getArticleAd();
            TextView title = (TextView) itemView.findViewById(R.id.home_listitem_title_name_tv);
            title.setText(R.string.hot_dynamic);
            ImageView icon = (ImageView) itemView.findViewById(R.id.home_listitem_title_iv);
            icon.setImageResource(R.drawable.ic_horn);
            TextView more = (TextView) itemView.findViewById(R.id.home_listitem_title_more_tv);
            more.setText(R.string.more_new);
            itemView.findViewById(R.id.home_listitem_title_more_ll).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (context instanceof MainActivity) {
                        MainActivity.setCurrentItem((MainActivity) context, 3);
                    }
                }
            });

            List<ArticleBean> articleList = data.getArticleList();
            if (articleAd != null && articleAd.getAd_position_id() != null) {
                View parentView = itemView.findViewById(R.id.holder_home_list_with_title_below_ll);
                parentView.setVisibility(View.VISIBLE);
                ImageView imageView = (ImageView) parentView.findViewById(R.id.item_article_ad_iv);
                ImageView icNew = (ImageView) parentView.findViewById(R.id.item_article_new_iv);
                icNew.setImageResource(R.drawable.ic_new);
                ImageUtil.loadUrl(requestManager, articleAd.getImages(), R.drawable.banner, imageView);
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                itemView.findViewById(R.id.item_article_time_iv).setVisibility(View.GONE);
                itemView.findViewById(R.id.item_article_number_tv).setVisibility(View.GONE);
                TextView tvTitle = (TextView) parentView.findViewById(R.id.item_article_content_tv);
                TextView tvEndTime = (TextView) parentView.findViewById(R.id.item_article_endtime_tv);
                tvTitle.setText(articleAd.getTitle());
                tvEndTime.setText(StringUtils.timeStamp10ToDate(articleAd.getUpdate_time(), StringUtils.DATE_FORMAT_CN));
                parentView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ArticleActivity.startActivity(context, articleAd.getAd_position_id(), FindFragment.ARTICLE_TYPE_NEWS);
                    }
                });
            }

            if (articleList != null && articleList.size() > 0) {
                MyGridView gridView = (MyGridView) itemView.findViewById(R.id.holder_home_list_with_title_table_gv);
                gridView.setNumColumns(2);
                gridView.setVerticalSpacing(DensityUtils.dip2px(context, 10));
                gridView.setHorizontalSpacing(DensityUtils.dip2px(context, 10));
                gridView.setPadding(gridView.getPaddingLeft(), gridView.getPaddingTop(), gridView.getPaddingRight(), DensityUtils.dip2px(context, 15));

                if (articleList.size() > DEFAULT_SHOW_SIZE_ARTICLE) {
                    articleList = articleList.subList(0, DEFAULT_SHOW_SIZE_ARTICLE);
                }
                gridView.setAdapter(new QuickTypeAdapter<ArticleBean>(context, articleList, R.layout.item_article) {
                    @Override
                    public void bindData4View(ViewHolder holder, final ArticleBean data, int type, int pos) {
                        bindArticleItem(context, holder, data, pos, FindFragment.ARTICLE_TYPE_NEWS);
                    }
                });
            }

            if (articleList == null || articleList.size() == 0) {
                itemView.findViewById(R.id.holder_home_list_with_title_bottom_v).setVisibility(View.GONE);
                itemView.findViewById(R.id.holder_home_list_with_title_top_v).setVisibility(View.GONE);
                itemView.findViewById(R.id.holder_home_list_with_title_base).setVisibility(View.GONE);
                itemView.findViewById(R.id.holder_home_list_with_title_above_ll).setVisibility(View.GONE);
            } else {
                itemView.findViewById(R.id.holder_home_list_with_title_bottom_v).setVisibility(View.VISIBLE);
                itemView.findViewById(R.id.holder_home_list_with_title_top_v).setVisibility(View.VISIBLE);
                itemView.findViewById(R.id.holder_home_list_with_title_base).setVisibility(View.VISIBLE);
            }
        }

        /**
         * 附近体育馆
         *
         * @param context
         * @param data
         */
        private void fillStore(final Context context, HomeBean data) {
            AdMainBean storeAd = data.getStoreAd();
            TextView title = (TextView) itemView.findViewById(R.id.home_listitem_title_name_tv);
            title.setText(R.string.nearby_store);
            ImageView icon = (ImageView) itemView.findViewById(R.id.home_listitem_title_iv);
            icon.setImageResource(R.drawable.ic_block);
            TextView more = (TextView) itemView.findViewById(R.id.home_listitem_title_more_tv);
            more.setText(R.string.more_store);
            itemView.findViewById(R.id.holder_home_list_with_title_bottom_v).setVisibility(View.VISIBLE);
            itemView.findViewById(R.id.holder_home_list_with_title_top_v).setVisibility(View.VISIBLE);
            itemView.findViewById(R.id.holder_home_list_with_title_base).setVisibility(View.VISIBLE);
            itemView.findViewById(R.id.home_listitem_title_more_ll).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    StoreListActivity.startActivity(context, StoreListActivity.TYPE_STORE);
                }
            });

            List<StoreBean> storeList = data.getStoreList();
            if (storeAd != null) {
                ImageView imageView = (ImageView) itemView.findViewById(R.id.holder_home_list_with_title_above_iv);
                itemView.findViewById(R.id.holder_home_list_with_title_above_ll).setVisibility(View.VISIBLE);
                ImageUtil.loadUrl(requestManager, storeAd.getImages(), R.drawable.banner, imageView);
            }

            if (storeList != null) {
                MyGridView gridView = (MyGridView) itemView.findViewById(R.id.holder_home_list_with_title_table_gv);

                if (storeList.size() > DEFAULT_SHOW_SIZE_STORE) {
                    storeList = storeList.subList(0, DEFAULT_SHOW_SIZE_STORE);
                }
                gridView.setAdapter(new QuickTypeAdapter<StoreBean>(context, storeList, R.layout.item_store) {
                    @Override
                    public void bindData4View(ViewHolder holder, StoreBean data, int type, int pos) {
                        bindStoreItem(context, holder, data, false);
                    }
                });
            }
        }


        /**
         * 教练
         *
         * @param context
         * @param data
         */
        private void fillCoach(final Context context, HomeBean data) {
            final AdMainBean coachAd = data.getCoachAd();
            TextView title = (TextView) itemView.findViewById(R.id.home_listitem_title_name_tv);
            title.setText(R.string.elite_coach);
            ImageView icon = (ImageView) itemView.findViewById(R.id.home_listitem_title_iv);
            icon.setImageResource(R.drawable.ic_medal);
            TextView more = (TextView) itemView.findViewById(R.id.home_listitem_title_more_tv);
            more.setText(R.string.more_coach);
            itemView.findViewById(R.id.home_listitem_title_more_ll).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    StoreListActivity.startActivity(context, StoreListActivity.TYPE_COACH);
                }
            });

            List<CoachBean> coachList = data.getCoachList();
            if (coachAd != null) {
                ImageView imageView = (ImageView) itemView.findViewById(R.id.holder_home_list_with_title_above_iv);
                itemView.findViewById(R.id.holder_home_list_with_title_above_ll).setVisibility(View.VISIBLE);
                ImageUtil.loadUrl(requestManager, coachAd.getImages(), R.drawable.banner, imageView);
            }

            if (coachList != null) {
                MyGridView gridView = (MyGridView) itemView.findViewById(R.id.holder_home_list_with_title_table_gv);

                if (coachList.size() > DEFAULT_SHOW_SIZE_COACH) {
                    coachList = coachList.subList(0, DEFAULT_SHOW_SIZE_COACH);
                }

                gridView.setAdapter(new QuickTypeAdapter<CoachBean>(context, coachList, R.layout.item_coach) {
                    @Override
                    public void bindData4View(ViewHolder holder, CoachBean data, int type, int pos) {
                        bindCoachItem(context, holder, data, pos);
                    }
                });
            }

            if (coachList == null || coachList.size() == 0) {
                itemView.findViewById(R.id.holder_home_list_with_title_bottom_v).setVisibility(View.GONE);
                itemView.findViewById(R.id.holder_home_list_with_title_top_v).setVisibility(View.GONE);
                itemView.findViewById(R.id.holder_home_list_with_title_base).setVisibility(View.GONE);
                itemView.findViewById(R.id.holder_home_list_with_title_above_ll).setVisibility(View.GONE);
            } else {
                itemView.findViewById(R.id.holder_home_list_with_title_bottom_v).setVisibility(View.VISIBLE);
                itemView.findViewById(R.id.holder_home_list_with_title_top_v).setVisibility(View.VISIBLE);
                itemView.findViewById(R.id.holder_home_list_with_title_base).setVisibility(View.VISIBLE);
            }
        }
    }

    public static void bindArticleItem(final Context context, final ViewHolder holder, final ArticleBean data, int pos, final int type) {

        if (type == FindFragment.ARTICLE_TYPE_NEWS) {
            holder.setVisibility(R.id.item_article_time_iv, View.GONE);
            holder.setVisibility(R.id.item_article_number_tv, View.GONE);
            if (TextUtils.equals("1", data.getIs_recommend())) {
                holder.setVisibility(R.id.item_article_new_iv, View.VISIBLE);
            } else {
                holder.setVisibility(R.id.item_article_new_iv, View.GONE);
            }
            holder.setText(R.id.item_article_endtime_tv, StringUtils.timeStampToDate(StringUtils.toInt(data.getTime()) * 1000L, new SimpleDateFormat(StringUtils.DATE_FORMAT_CN)));
        } else {
            holder.setVisibility(R.id.item_article_time_iv, View.VISIBLE);
            holder.setVisibility(R.id.item_article_number_tv, View.VISIBLE);
            holder.setVisibility(R.id.item_article_new_iv, View.GONE);
            String userNum = data.getUser_num() == null ? "0" : data.getUser_num();
            SpannableString spannableString = new SpannableString(String.format("已报名%s人", userNum));
            ForegroundColorSpan colorSpan = new ForegroundColorSpan(COLOR_YELLOW);
            spannableString.setSpan(colorSpan, 3, 3 + userNum.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            holder.setText(R.id.item_article_number_tv, spannableString);
            if (System.currentTimeMillis() > StringUtils.toInt(data.getEnd_time()) * 1000L) {
                holder.setText(R.id.item_article_endtime_tv, "活动已经结束");
            } else {
                String tillTime = String.valueOf((StringUtils.toInt(data.getEnd_time()) * 1000L - System.currentTimeMillis()) / 1000 / 60 / 60 / 24);
                SpannableString span = new SpannableString(String.format("%s天后结束报名", tillTime));
                span.setSpan(colorSpan, 0, tillTime.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                holder.setText(R.id.item_article_endtime_tv, span);
            }

        }


        holder.setImg(context, R.id.item_article_ad_iv, data.getImage());
        holder.setText(R.id.item_article_content_tv, data.getTitle());


        holder.getParentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArticleActivity.startActivity(context, data.getId(), type);
            }
        });

    }

    /**
     * banner item
     *
     * @param itemView
     * @param requestManager
     * @param banner
     * @param leftView
     * @param rightView
     * @param list
     */

    public static final String TYPE_STORE = "1";
    public static final String TYPE_ACTIVE = "2";
    public static final String TYPE_NEWS = "3";
    public static final String TYPE_ACTIVE_STADIUM = "4";

    public static void bindBannerItem(final View itemView,
                                      final RequestManager requestManager,
                                      final Banner banner,
                                      View leftView,
                                      View rightView,
                                      final List<AdMainBean> list) {
        banner.setImages(list).setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                if (path != null && path instanceof AdMainBean) {
                    AdMainBean data = (AdMainBean) path;
                    ImageUtil.loadUrl(requestManager, data.getImages(), R.drawable.banner, imageView).getRequest();
                }
            }

            @Override
            public ImageView createImageView(Context context) {
                ImageView imageView = new ImageView(context);
                imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DensityUtils.dip2px(context, 145)));
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                return imageView;
            }
        }).start();


        leftView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                banner.prevPage();
            }
        });

        rightView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                banner.nextPage();
            }
        });

        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                if (TextUtils.equals(TYPE_STORE, list.get(position).getAd_position_id())) {
                    StoreActivity.startActivity(itemView.getContext(), list.get(position).getForeign_id());
                } else if (TextUtils.equals(TYPE_ACTIVE, list.get(position).getAd_position_id())) {
                    ArticleActivity.startActivity(itemView.getContext(), list.get(position).getForeign_id(), FindFragment.ARTICLE_TYPE_ACT);
                } else if (TextUtils.equals(TYPE_NEWS, list.get(position).getAd_position_id())) {
                    ArticleActivity.startActivity(itemView.getContext(), list.get(position).getForeign_id(), FindFragment.ARTICLE_TYPE_NEWS);
                } else if (TextUtils.equals(TYPE_ACTIVE_STADIUM, list.get(position).getAd_position_id())) {
                    ArticleStoreActivity.startActivity(itemView.getContext(), list.get(position).getForeign_id());
                } else {
                    ArticleActivity.startActivity(itemView.getContext(), list.get(position).getForeign_id(), FindFragment.ARTICLE_TYPE_ACT);
                }
            }
        });
    }

    /**
     * 绑定分类信息
     *
     * @param context
     * @param holder
     * @param data
     * @param pos
     * @param size
     */
    public static void bindCategoryItem(final Context context, final ViewHolder holder, final CategoryBean data, int pos, int size) {
        holder.setText(R.id.item_home_gridview_tv, data.getTitle());
        Glide.with(context).load(data.getIcon().replace("\\", "/")).into((ImageView) holder.getView(R.id.item_home_gridview_iv));
        int column = 5;
        if (pos / column >= (size / column - (size % column == 0 ? 1 : 0))) {
            holder.getView(R.id.item_home_gridview_line_v).setVisibility(View.GONE);
        } else {
            holder.getView(R.id.item_home_gridview_line_v).setVisibility(View.VISIBLE);
        }
        holder.getParentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StoreListActivity.startActivity(context, StoreListActivity.TYPE_STORE, data.getId());
            }
        });
    }

    /**
     * 加载店铺item
     *
     * @param context
     * @param holder
     * @param data
     */
    public static void bindStoreItem(final Context context, final ViewHolder holder, final StoreBean data, boolean isStoreActivity) {
        holder.setImg(context, R.id.item_store_store_icon_iv, data.getStadiumpic());
        holder.setText(R.id.item_store_store_name_tv, data.getStadiumname());
        holder.setText(R.id.item_store_distance_tv, data.getDistance());
        holder.setText(R.id.item_store_store_address_tv, data.getStadiumaddress());
        RatingBar ratingBar = holder.getView(R.id.item_store_ratingbar);
        ratingBar.setRating(5.0f - StringUtils.toFloat(data.getEval()));
        if (isStoreActivity && data.getIs_buy().equals("1")) {
            holder.getView(R.id.item_store_store_gone_iv).setVisibility(View.VISIBLE);
        } else {
            holder.getView(R.id.item_store_store_gone_iv).setVisibility(View.GONE);
        }
        LinearLayout imagePanel = holder.getView(R.id.item_store_icons_ll);
        imagePanel.removeAllViews();
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(DensityUtils.dip2px(context, 15), DensityUtils.dip2px(context, 15));
        layoutParams.setMargins(0, 0, DensityUtils.dip2px(context, 3), 0);
        for (int i = 0; i < data.getCategory().size(); i++) {
            final ImageView imageView = new ImageView(context);
            imageView.setBackgroundResource(R.drawable.black_border);
            Glide.with(context).load(data.getCategory().get(i).replace("\\", "/")).into(imageView);
            imageView.setLayoutParams(layoutParams);
            imagePanel.addView(imageView);
        }

        holder.getParentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StoreActivity.startActivity(context, data.getSid());
            }
        });
    }

    /**
     * 加载教练item
     *
     * @param context
     * @param holder
     * @param data
     * @param pos
     */

    public static void bindCoachItem(final Context context, final ViewHolder holder, final CoachBean data, int pos) {
        holder.setImg(context, R.id.item_coach_icon_iv, data.getAvatar());
        holder.setText(R.id.item_coach_name_tv, data.getCoach_name());
        holder.setText(R.id.item_coach_time_tv, data.getPrice() + "/次");
        holder.setText(R.id.item_coach_address_tv, data.getArea());
        RatingBar ratingBar = holder.getView(R.id.item_coach_ratingbar);
        ratingBar.setIsIndicator(true);
        ratingBar.setRating(StringUtils.toFloat(data.getEval()));
        if (TextUtils.equals(data.getIs_hot(), "1")) {
            holder.setVisibility(R.id.item_coach_hot_tv, View.VISIBLE);
        } else {
            holder.setVisibility(R.id.item_coach_hot_tv, View.INVISIBLE);
        }
        List<String> label = data.getCategory_list() == null ? new ArrayList<String>() : data.getCategory_list();
        MyGridView gridInner = holder.getView(R.id.item_coach_types_gv);
        gridInner.setNumColumns(3);
        gridInner.setVerticalSpacing(DensityUtils.dip2px(context, 5));
        gridInner.setHorizontalSpacing(DensityUtils.dip2px(context, 5));
        gridInner.setAdapter(new QuickAdapter<String>(context, R.layout.item_tag, label) {

            @Override
            public void bindData4View(final ViewHolder innerHolder, String data, int pos) {
                innerHolder.setText(R.id.text, data.length() > 3 ? data.substring(0, 3) : data);
                innerHolder.getParentView().setOnTouchListener(new View.OnTouchListener() {

                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        holder.getParentView().performClick();
                        return false;
                    }
                });
            }
        });


        holder.getParentView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CoachDetailActivity.startActivity(context, data.getCoach_id());
            }
        });
    }
}
